﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Option.Master" AutoEventWireup="true"
    CodeBehind="UserSetting.aspx.cs" Inherits="MsgCenter.Web.Pages.UserGroup.UserSetting" %>

<asp:Content ID="Content1" ContentPlaceHolderID="headContent" runat="server">
    <script type="text/javascript" src="<%=ResolveClientUrl("~/JavaScript/FirePlat/assets/js/ace.min.js") %>"></script>
    <script type="text/javascript" src="<%=ResolveClientUrl("~/JavaScript/FirePlat/assets/js/ace-extra.min.js") %>"></script>
    <script type="text/javascript" src="<%=ResolveClientUrl("~/JavaScript/FirePlat/assets/js/bootstrap.min.js") %>"></script>
    <script type="text/javascript" src="<%=ResolveClientUrl("~/JavaScript/FirePlat/assets/js/ace-elements.min.js") %>"></script>
    <link rel="stylesheet" media="screen" type="text/css" href="<%=ResolveClientUrl("~/JavaScript/Tree/tree.css") %>" />
    <script type="text/javascript" src="<%=ResolveClientUrl("~/JavaScript/Tree/tree.js") %>"></script>
    <script type="text/javascript" src="<%=ResolveClientUrl("~/JavaScript/FirePlat/assets/js/jqGrid/i18n/grid.locale-cn.js") %>"></script>
    <script type="text/javascript" src="<%=ResolveClientUrl("~/JavaScript/FirePlat/assets/js/jqGrid/jquery.jqGrid.min.js") %>"></script>
    <script type="text/javascript" src="<%=ResolveClientUrl("~/JavaScript/FirePlat/assets/js/jqGrid/myJqgrid.js") %>"></script>
    <script type="text/javascript">
        var varGroupID = "<%=strGroupID %>";
        function getCalendarData() {
            var trdata = null;
            $.ajax({
                type: "GET",
                url: "../../Handlers/Handler_Dept.ashx?method=GetDeptTree",
                async: false,
                success: function (msg)
                { trdata = msg; },
                error: function (msg) { }
            });
            return trdata;
        }
        function LoadTree() {
            var o = {
                cbiconpath: "../../Images/tree/",
                emptyiconpath: "../../Images/tree/s.gif",
                showcheck: false,
                onnodeclick: function (item) {
                    var deptID = "";
                    if (item.value != "00000000-0000-0000-0000-000000000000" && item.id != "000001") {
                        deptID = item.value;
                    }
                    $("#" + gridTableID).jqGrid('setGridParam', {
                        postData: { 'DeptGuID': deptID }, //发送数据  
                        page: 1
                    }).trigger("reloadGrid"); //重新载入
                }
            };
            var tre = getCalendarData();
            eval("var data =" + tre + ";");
            o.data = data;
            $("#tree").treeview(o);
        }
        $(document).ready(function () {
            LoadTree();
            GetUserGroup();
        });

        var gridTableID = 'grid-table';
        var gridPagerID = 'grid-pager';
        var ajaxUrl = "../../Handlers/Handler_User.ashx";
        jQuery(function ($) {
            var url = ajaxUrl + "?method=GetUserALLList&GroupID=" + varGroupID;
            var colNames = ['UserID', '用户名称', '所属部门'];
            var colModel = [
				{ name: 'UserID', index: 'UserID', width: 50, editable: false, hidden: true },
				{ name: 'Name', index: 'Name', width: 12, editable: false, stype: 'text', searchoptions: { sopt: ['eq', 'ne', 'cn', 'nc']} },
				{ name: 'DeptName', index: 'DeptName', width: 30, editable: false, stype: 'text', searchoptions: { sopt: ['eq', 'ne', 'cn', 'nc']} }
			];
            var dfop =
            {
                rownumbers: true,
                GridID: gridTableID,
                GridPagerID: null,
                Url: url,
                ColNames: colNames,
                ColModel: colModel,
                Caption: "用户列表",
                SortName: "CreateDate",
                Height: 400,
                RowNum: 1000
            };
            showJqGrid(dfop);
        });
        function Reload() {
            $("#" + gridTableID).trigger("reloadGrid");
        }

        function SetUserGroup() {
            if (varGroupID == "") {
                showDialogMessage("分组传入参数出现错误!");
                return;
            }
            var row = $("#" + gridTableID).jqGrid('getGridParam', 'selarrrow');
            if (row.length > 0) {
                var len = row.length;
                var selectUserID = "";
                for (var i = 0; i < len; i++) {
                    var model = $("#" + gridTableID).jqGrid('getRowData', row[i]);
                    if (selectUserID == "") {
                        selectUserID = model.UserID;
                    }
                    else {
                        selectUserID += "," + model.UserID;
                    }
                }
                if (selectUserID == "") {
                    showDialogMessage("请先选择用户数据!");
                }
                else {
                    $.ajax({
                        type: 'POST',
                        url: "../../Handlers/Handler_UserGroup.ashx?method=SetUserGroup",
                        data: { 'UserID': selectUserID, 'GroupID': varGroupID },
                        success: function (msg) {
                            GetUserGroup();
                            Reload();
                        },
                        error: function (msg) {
                        }
                    });
                }
            }
            else {
                showDialogMessage("请先选择用户数据!");
            }
            return false;
        }

        function GetUserGroup() {
            $.ajax({
                type: "GET",
                url: "../../Handlers/Handler_UserGroup.ashx?method=GetGroupUser&GroupID=" + varGroupID,
                success: function (msg) {
                    $("#divSelectUser").empty();
                    if (msg == "\"\"") {
                    }
                    else {
                        var obj2 = eval('(' + msg + ')');
                        $("#divSelectUser").append("<br>");
                        $.each(obj2, function (index, item) {
                            $("#divSelectUser").append("<div class=\"alert alert-block alert-success\" style=\"padding: 5px; margin-bottom: 5px;height: 30px;\">"
                           + " <button type=\"button\" class=\"close\" data-dismiss=\"alert\" onclick=\"return DeleteGroupUser('" + item.UserID + "','" + item.GroupID + "');\"><i class=\"icon-remove\"></i></button><i class=\"icon-ok green\"></i>" + item.Name + "</div>");
                        });
                    }
                },
                error: function (msg) { }
            });
        }
        function DeleteGroupUser(userid, groupid) {
            $.ajax({
                type: "GET",
                url: "../../Handlers/Handler_UserGroup.ashx?UserID=" + userid + "&GroupID=" + groupid,
                data: { method: "DeleteGroupUser" },
                success: function (msg) {
                    GetUserGroup();
                    Reload();
                },
                error: function (msg) {

                }
            });
            return false;
        }
        function CloseBox() {
            parent.Reload();
            parent.CBClose();
        }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="mailContent" runat="server">
    <div class="row">
        <div class="col-xs-3">
            <div class="widget-box">
                <div class="widget-header header-color-blue2">
                    <h4 class="lighter smaller">
                        部门列表</h4>
                </div>
                <div class="widget-body">
                    <div class="widget-main padding-8">
                        <div id="tree" style="height: 400px; overflow-x: no; overflow-y: auto;">
                            <img src="../../Images/tree/loading.gif" />
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-xs-4">
            <div class="row">
                <div class="col-xs-12">
                    <div class="widget-body" style="height: 460px">
                        <table id="grid-table">
                        </table>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-xs-2">
            <div class="widget-box">
                <div class="widget-header header-color-blue2">
                    <h4 class="lighter smaller">
                        功能操作</h4>
                </div>
                <div class="widget-body">
                    <div class="widget-main padding-8" style="height: 415px">
                        <br />
                        <br />
                        <br />
                        <br />
                        <div class="row">
                            <div class="col-xs-12">
                                <button class="btn btn-sm btn-success" onclick="return SetUserGroup();">
                                    <i class="icon-ok bigger-110"></i>添加人员 <i class="icon-arrow-right icon-on-right">
                                    </i>
                                </button>
                                <br />
                                <br />
                                <br />
                                <br />
                                <br />
                                <br />
                                <button class="btn btn-danger btn-block" onclick="return CloseBox();">
                                    关闭窗体</button>
                            </div>
                        </div>
                        <%--<br />
                        <div class="row">
                            <div class="col-xs-12">
                                <button class="btn btn-sm btn-danger">
                                    <i class="icon-trash bigger-110"></i>移除人员 <i class="icon-arrow-left icon-on-left">
                                    </i>
                                </button>
                            </div>
                        </div>--%>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-xs-3">
            <div class="widget-box">
                <div class="widget-header header-color-blue2">
                    <h4 class="lighter smaller">
                        已选人员</h4>
                </div>
                <div class="widget-body" style="height: 415px">
                    <div class="col-xs-12" id="divSelectUser">
                        <%-- <br />
                        <div class="alert alert-block alert-success" style="padding: 5px; margin-bottom: 5px;
                            height: 30px;">
                            <button type="button" class="close" data-dismiss="alert">
                                <i class="icon-remove"></i>
                            </button>
                            <i class="icon-ok green"></i>欢迎使用
                        </div>
                        <div class="alert alert-block alert-success" style="padding: 5px; margin-bottom: 5px;
                            height: 30px;">
                            <button type="button" class="close" data-dismiss="alert">
                                <i class="icon-remove"></i>
                            </button>
                            <i class="icon-ok green"></i>欢迎使用1
                        </div>--%>
                    </div>
                </div>
            </div>
        </div>
    </div>
    </div>
</asp:Content>
